package org.codefinger.json.parser.converter;

import java.util.Collection;

import org.codefinger.json.parser.JSONArrayDeserializer;
import org.codefinger.json.parser.JSONConverter;
import org.codefinger.json.parser.JSONConverterType;
import org.codefinger.json.parser.JSONDeserializer;
import org.codefinger.json.parser.JSONObjectDeserializer;
import org.codefinger.json.parser.JSONParser;

public class ConverterFromCollection implements JSONConverter {

	public static final ConverterFromCollection	INSTANCE	= new ConverterFromCollection();

	private ConverterFromCollection() {

	}

	@Override
	public Object convert(Object value, JSONDeserializer deserializer) {
		return null;
	}

	@Override
	public Object convert(Object value, JSONObjectDeserializer objectDeserializer) {
		return null;
	}

	@Override
	public Object convert(Object value, JSONArrayDeserializer arrayDeserializer) {
		Collection<?> collection = (Collection<?>) value;
		for (Object item : collection) {
			if (item == null) {
				arrayDeserializer.addNullValue();
				continue;
			}
			JSONParser.addItem(item, arrayDeserializer);
		}
		return arrayDeserializer.getDeserializedValue();
	}

	@Override
	public void setItemValue(Object value, JSONObjectDeserializer objectDeserializer) {

	}

	@Override
	public void addItemValue(Object value, JSONArrayDeserializer arrayDeserializer) {

	}

	@Override
	public JSONConverterType jsonConverterType() {
		return JSONConverterType.Array;
	}

}
